#!/bin/bash

# postinst script for driver-serial-usbser-edge
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chown root:sys $BASEDIR/kernel
	chown root:sys $BASEDIR/kernel/drv
	chown root:sys $BASEDIR/kernel/drv/amd64
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/usbser_edge.conf ] && rm -f $BASEDIR/kernel/drv/usbser_edge.conf
	else
	    [ -f $BASEDIR/kernel/drv/usbser_edge.conf ] || cp -ax $BASEDIR/usr/share/doc/driver-serial-usbser-edge/examples/usbser_edge.conf $BASEDIR/kernel/drv/usbser_edge.conf
	    chmod 0644 "$BASEDIR/kernel/drv/usbser_edge.conf"
	    chown root:sys "$BASEDIR/kernel/drv/usbser_edge.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/usbser_edge ] && rm -f $BASEDIR/kernel/drv/amd64/usbser_edge
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/usbser_edge"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/usbser_edge"
	fi
	[ "$ZONEINST" = "1" ] || (grep -c "^usbser_edge " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -i '"usbif1608,1.100.config1.0" "usbif1608,1.config1.0" "usbif1608,3.config1.0" "usbif1608,4.config1.0" "usbif1608,5.config1.0" "usbif1608,6.config1.0" "usbif1608,7.config1.0" "usbif1608,c.config1.0" "usbif1608,d.config1.0" "usbif1608,e.config1.0" "usbif1608,f.config1.0" "usbif1608,10.config1.0" "usbif1608,11.config1.0" "usbif1608,12.config1.0" "usbif1608,13.config1.0" "usbif1608,14.config1.0" "usbif1608,201.config1.0" "usbif1608,205.config1.0" "usbif1608,206.config1.0" "usbif1608,207.config1.0" "usbif1608,20c.config1.0" "usbif1608,20d.config1.0" "usbif1608,215.config1.0" "usbif1608,217.config1.0" "usbif1608,21a.config1.0" "usbif1608,240.config1.0" "usbif1608,241.config1.0" "usbif1608,242.config1.0" "usbif1608,243.config1.0" "usbif1608,244.config1.0" "usbif1608,247.config1.0"' -m '* 0666 root sys' usbser_edge ) )
	
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

